package cn.edu.fudan.test;

import cn.edu.fudan.data.ReadData;
import cn.edu.fudan.data.WriteData;
import cn.edu.fudan.tools.GetConfig;
import cn.edu.fudan.type.*;
import org.apache.log4j.Logger;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 80494 on 2017/3/14.
 * this file extract every pamap event files;
 */
public class ExractEventData {
    private static Logger logger = Logger.getLogger(ExractEventData.class);

    //private static final String subject = "subject101";
    //private static Activities lable = Activities.walking;
    //private static PAMAPDimension dimension = PAMAPDimension.z_ankle;

    public static void main(String[] args) throws IOException {

        Config config = new GetConfig().getConfig();
        String path = config.getPath();
        //FileWriter fw = new FileWriter(path+" time_overview");

        for (Subject subject : Subject.values()
                ) {


            String filePath = path + subject + "_extract";
            for (PAMAPDimension dimension : PAMAPDimension.values()) {
                for (Activities lable : Activities.values()) {


                    ReadData readData = new ReadData();
                    //ExtractFeature extractFeature = new ExtractFeature();
                    //HandelFeature handelFeature = new HandelFeature();
                    WriteData writeData = new WriteData();
                    //SlideWindow slideWindow = new SlideWindow();
                    //HandleDistance handleDistance = new HandleDistance();
                    ArrayList<Double> timedata = new ArrayList<Double>();
                    List<DataItem> data = new ArrayList<DataItem>();
                    BeginEndTime bet = new BeginEndTime();
                    FileWriter fw = new FileWriter("E:\\BEC\\PAMAP2_Dataset\\PAMAP2_Dataset\\Protocol\\result-1\\"
                            +" "+subject+" "+lable+" "+dimension);
                    try {
                        //data = readData.readPAMAPDataFromFile(filePath, true, dimension);
                        data = readData.readPAMAPDataFromFile(filePath,dimension);
                        //this "true" means converter all negative number to 0 ,
                        // if "false" then converter all positive number to 0
                        bet = readData.readPAMAPTimeFile(filePath, lable);
                    } catch (IOException e) {
                    }
                    for(int i=0 ; i< data.size();i++){
                        if(data.get(i).getTimestamp()>=bet.getBegin()*10000 && data.get(i)
                                .getTimestamp()<=bet.getEnd()*10000){
                            timedata.add(data.get(i).getValue());
                        }
                    }
                    fw.write(timedata.toString().replace("[","").replace("]",""));
                    fw.close();
                    System.out.println(1);
                    //fw.write(subject+"  " +lable+"   "+dimension+"  " +bet.getBegin()+"  "+bet.getEnd()+"\n");
                    //System.out.println(1);

                    //System.out.println(subject+"  " +lable+"   "+dimension+"  " +bet.getBegin()+"  "+bet.getEnd());
                    //
                    // writeData.writeData(path+"aaa"+subject+lable+dimension,data);
                    //writeData.writeDataUCRFormat(path+"\\/"+subject+"_"+lable ,data,lable.ordinal(),bet);

                }
            }
        }
        //fw.close();

    }
}